﻿CREATE PROCEDURE [dbo].[UpdateActivity]
	@ActivityId uniqueidentifier,
	@Tags nvarchar(max),
	@Description nvarchar(max),
	@Category uniqueidentifier,
	@ResponsiblePerson uniqueidentifier,
	@Priority int,
	@Progress int,
	@Quality int,
	@IsCompleted bit,
	@StartDate datetime,
	@DueDate datetime,
	@Ended datetime,
	@IsTemplate bit,
	@IsHierarchical bit,
    @IsDeleted bit,
    @LastChanged datetime,
	@LastChangedBy uniqueidentifier,

	@TimeStamp timestamp,
	@newTimeStamp timestamp output

AS

	UPDATE Activity 

	SET 

	 Tags = @Tags, 
	 [Description] = @Description, 
	 Category = @Category, 
	 ResponsiblePerson = @ResponsiblePerson,
	 [Priority] = @Priority, 
	 Progress = @Progress,
	 Quality = @Quality,
	 IsCompleted = @IsCompleted, 
	 StartDate = @StartDate, 
	 DueDate = @DueDate, 
	 Ended = @Ended,
	 IsTemplate = @IsTemplate, 
	 IsHierarchical = @IsHierarchical, 
	 IsDeleted = @IsDeleted, 
	 LastChanged = @LastChanged,
	 LastChangedBy = @LastChangedBy

	WHERE ActivityId = @ActivityId AND [TimeStamp]=@TimeStamp

  IF @@ROWCOUNT = 0

    RAISERROR('Row has been edited by another user', 16, 1)            	


	SELECT @newTimeStamp = [TimeStamp]

	FROM Activity 

	WHERE ActivityId = @ActivityId

RETURN 0